package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

import com.alibaba.fastjson2.JSON;
import com.elder.business.domain.ElderlyApartmentActivitiesVO;
import com.elder.common.annotation.Anonymous;
import com.elder.common.utils.LongUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.business.domain.ElderlyApartmentActivities;
import com.elder.business.service.IElderlyApartmentActivitiesService;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 公寓活动Controller
 * 
 * @author zyk
 * @date 2023-11-26
 */
@RestController
@RequestMapping("")
public class ElderlyApartmentActivitiesController extends BaseController
{
    @Autowired
    private IElderlyApartmentActivitiesService elderlyApartmentActivitiesService;

    /**
     * 查询公寓活动列表
     */
    @Anonymous
    @RequestMapping("/business/activities/list")
    public TableDataInfo list(String startTime,String endTime,String activityName,String leaderName, Integer pageNum,Integer pageSize,String applyStatus){
        return elderlyApartmentActivitiesService.getApartmentActivitiesList(startTime,endTime,activityName,leaderName,pageNum,pageSize,applyStatus);
    }

    /**
     * 导出公寓活动列表
     */
    @Anonymous
    @Log(title = "公寓活动", businessType = BusinessType.EXPORT)
    @PostMapping("/business/activities/export")
    public void export(HttpServletResponse response, ElderlyApartmentActivities elderlyApartmentActivities)
    {
        List<ElderlyApartmentActivities> list = elderlyApartmentActivitiesService.selectElderlyApartmentActivitiesList(elderlyApartmentActivities);
        ExcelUtil<ElderlyApartmentActivities> util = new ExcelUtil<ElderlyApartmentActivities>(ElderlyApartmentActivities.class);
        util.exportExcel(response, list, "公寓活动数据");
    }

    /**
     * 获取公寓活动详细信息
     */
    @Anonymous
    @GetMapping(value = "/business/activities/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId)
    {
        return success(elderlyApartmentActivitiesService.selectElderlyApartmentActivitiesById(activityId));
    }

    /**
     * 新增公寓活动
     */
    @Anonymous
    @Log(title = "公寓活动", businessType = BusinessType.INSERT)
    @PostMapping("/business/activities")
    public AjaxResult add(@RequestBody ElderlyApartmentActivitiesVO elderlyApartmentActivities)
    {
        return toAjax(elderlyApartmentActivitiesService.insertElderlyApartmentActivities(elderlyApartmentActivities));
    }

    /**
     * 修改公寓活动
     */
    @Anonymous
    @Log(title = "公寓活动", businessType = BusinessType.UPDATE)
    @PutMapping("/business/activities")
    public AjaxResult edit(@RequestBody ElderlyApartmentActivitiesVO elderlyApartmentActivities)
    {
        return toAjax(elderlyApartmentActivitiesService.updateElderlyApartmentActivities(elderlyApartmentActivities));
    }

    /**
     * 删除公寓活动
     */
    @Anonymous
    @Log(title = "公寓活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/business/activities/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(elderlyApartmentActivitiesService.deleteElderlyApartmentActivitiesByIds(ids));
    }

    /***
     * @description 上传活动视频
     * @param
     * @return String
     * @author zyk
     * @date 2024/2/24 10:46
     */
    @Anonymous
    @RequestMapping("/business/activities/uploadActVideo")
    public String uploadActVideo(@RequestBody ElderlyApartmentActivitiesVO elderlyApartmentActivitiesVO){
        return JSON.toJSONString(elderlyApartmentActivitiesService.uploadActVideo(elderlyApartmentActivitiesVO));
    }

    /***
     * @description 获取活动视频
     * @param
     * @return String
     * @author zyk
     * @date 2024/2/24 10:46
     */
    @Anonymous
    @RequestMapping("/business/activities/activitiesVideo")
    public String activitiesVideo(@RequestBody ElderlyApartmentActivitiesVO elderVideo) {
        return JSON.toJSONString(elderlyApartmentActivitiesService.getActivitiesVideo(LongUtils.str2Long(elderVideo.getActivityId())));
    }

    @Anonymous
    @RequestMapping("/business/activities/approval")
    public AjaxResult approval(String activityId, String applyStatus,String notes){
        return elderlyApartmentActivitiesService.approval(LongUtils.str2Long(activityId),applyStatus,notes);
    }
}
